package com.allchips.pin.controller;

import com.allchips.pin.dto.PinDTO;
import com.allchips.pin.dto.PinParamDTO;
import com.allchips.pin.util.PinMatchUtil;
import com.allchips.pin.util.ThreadLocalUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping
public class PinController {

    @RequestMapping("/search")
    public PinDTO search(@RequestBody PinParamDTO pinParamDTO) {
        PinDTO rtn = new PinDTO();
        try {
            ThreadLocalUtil.get().set("pinParam", pinParamDTO);
            PinDTO pinDTO = PinMatchUtil.searchNew(pinParamDTO);
            if (pinDTO == null) {
                pinDTO = rtn;
            }
            return pinDTO;
        } catch (Exception e) {
           log.error("报错了",e);
        }finally {
            ThreadLocalUtil.remove();
        }
        return rtn;
    }

}